//
//  BTEListATableViewCell.swift
//  BTE
//  列表头部
//  Created by Mike Zhang on 2025/8/19.
//

import UIKit

class BTEListATableViewCell: UITableViewCell {
    
    var model: BTHOMtiniestmodel?{
        didSet {
            guard let m = model else {
                return
            }
            
            a1.text = m.plumiped
            a2.text = m.tergal
            a3.text = m.cesura
            a4.text = m.civilizations
            bt.setTitle(title: m.allergin ?? "")
            
            leftim.sd_setImage(with: URL.init(string: m.butyrins ?? ""))
            letttt.text = m.cuspid
        }
    }
    
    let leftim = UIImageView.init()
    let letttt = UILabel()
    let leftbte = UILabel()
    
    let rightima = UIImageView.init(image: UIImage.init(named: "Framefewfwefewfewfew33333"))
    
    let bgimage = UIImageView.init(image: UIImage.init(named: "Group 117127fffffff6903"))
    
    let bt = UIButton()
    
    let a1 = UILabel()
    
    let a2 = UILabel()
    
    let a3 = UILabel()
    
    let a4 = UILabel()
    
    let buttonview = UIView()
    
    let tiel = UILabel()

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        selectionStyle = .none
        
        backgroundColor = .clear
        
        bt.isUserInteractionEnabled = false
        
        contentView.backgroundColor = .clear
        
        contentView.addSubview(leftim)
        contentView.addSubview(letttt)
        contentView.addSubview(leftbte)
        
        contentView.addSubview(rightima)
        contentView.addSubview(bgimage)
        contentView.addSubview(bt)
        
        leftim.roundCorners(.allCorners, radius: 12)
        leftim.snp.makeConstraints { make in
            make.width.height.equalTo(34)
            make.left.equalToSuperview().offset(16)
            make.top.equalToSuperview()
        }
        
        letttt.textColor = .black
        letttt.font = .systemFont(ofSize: 20, weight: .bold)
        letttt.snp.makeConstraints { make in
            make.centerY.equalTo(leftim)
            make.left.equalTo(leftim.snp.right).offset(19)
        }
        
        leftbte.text = BTELanguageManager.shared.localizedString(forKey: "Hello! Welcome To Pinjaman Instan!")
        leftbte.textColor = .colorWithHex("#333333")
        leftbte.font = .systemFont(ofSize: 16, weight: .regular)
        leftbte.snp.makeConstraints { make in
            make.left.equalTo(leftim)
            make.top.equalTo(leftim.snp.bottom).offset(8)
        }
        
        rightima.snp.makeConstraints { make in
            make.top.equalTo(leftim)
            make.right.equalToSuperview().offset(-16)
        }
        
        bgimage.snp.makeConstraints { make in
            make.left.equalTo(leftim)
            make.right.equalToSuperview().offset(-16)
            make.top.equalTo(leftbte.snp.bottom).offset(10)
            make.height.equalTo((UIScreen.main.bounds.width-32) * bgimage.frame.height / bgimage.frame.width)
        }
        
        bt.backgroundColor = .colorWithHex("#39B4E6")
        bt.roundCorners(.allCorners, radius: 52/2)
        bt.setFont(.systemFont(ofSize: 18, weight: .bold))
        bt.layer.borderColor = UIColor.colorWithHex("#6C2724")?.cgColor
        bt.layer.borderWidth = 3
        bt.setTitleColor(.white)
        bt.snp.makeConstraints { make in
            make.height.equalTo(52)
            make.width.equalTo(303)
            make.top.equalTo(bgimage.snp.bottom).offset(-(52/2))
            make.centerX.equalToSuperview()
        }
        
        a1.font = .systemFont(ofSize: 14, weight: .medium)
        a2.font = .systemFont(ofSize: 36, weight: .bold)
        a3.font = .systemFont(ofSize: 16, weight: .medium)
        a4.font = .systemFont(ofSize: 16, weight: .medium)
        
        [a1,a2,a3,a4].forEach { item in
            item.textColor = .black
            bgimage.addSubview(item)
        }
        
        a1.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(26)
            make.top.equalToSuperview().offset(26)
        }
        
        a2.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(26)
            make.top.equalTo(a1.snp.bottom).offset(6)
        }
        
        bgimage.addSubview(buttonview)
        buttonview.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.bottom.equalTo(bt.snp.top).offset(-20)
        }
        
        
        let a1im = UIView()
        buttonview.addSubview(a1im)
        a1im.snp.makeConstraints { make in
            make.left.equalToSuperview()
            make.top.bottom.equalToSuperview()
        }
        
        let a1image = UIImageView.init(image: UIImage.init(named: "Group 1171276662fewfewfw33333"))
        a1im.addSubview(a1image)
        a1image.snp.makeConstraints { make in
            make.top.left.bottom.equalToSuperview()
            make.height.equalTo(30)
        }
        
        a1im.addSubview(a3)
        a3.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.right.equalToSuperview()
            make.left.equalTo(a1image.snp.right).offset(12)
        }
        
        let a2im = UIView()
        buttonview.addSubview(a2im)
        a2im.snp.makeConstraints { make in
            make.right.equalToSuperview()
            make.top.bottom.equalToSuperview()
            make.left.equalTo(a1im.snp.right).offset(40)
        }
        
        let a2image = UIImageView.init(image: UIImage.init(named: "Group 117127ffeeeeww6885"))
        a2im.addSubview(a2image)
        a2image.snp.makeConstraints { make in
            make.top.left.bottom.equalToSuperview()
            make.height.equalTo(30)
            make.width.equalTo(30)
        }
        
        a2im.addSubview(a4)
        a4.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.right.equalToSuperview()
            make.left.equalTo(a2image.snp.right).offset(12)
        }
        
        
        tiel.text = BTELanguageManager.shared.localizedString(forKey: "Popular recommendations")
        tiel.font = .systemFont(ofSize: 18, weight: .bold)
        tiel.textColor = .black
        contentView.addSubview(tiel)
        tiel.snp.makeConstraints { make in
            make.bottom.equalToSuperview().offset(-18)
            make.left.equalToSuperview().offset(16)
            make.top.equalTo(bt.snp.bottom).offset(18)
        }
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
